Pro ASP.NET Web API: HTTP Web Services in ASP.NET by Tugberk Ugurlu & Alexander Zeitler
Author:Tugberk Ugurlu & Alexander Zeitler [Ugurlu, Tugberk & Zeitler, Alexander]
Language: eng
Format: epub
Tags: C#, Computers, Programming, Microsoft, Programming Languages
ISBN: 9781430247258
Publisher: Apress
Published: 2013-09-25T04:00:00+00:00
Figure 10-1. Russian Doll Model of the DelegatingHandler pipeline
As can be seen in Figure 10-1, the outermost doll (DelegatingHandler) is the HttpServer class, which itself just derives from DelegatingHandler.
The next DelegatingHandler implementation to be invoked is the DelegatingHandler1, which is a custom implementation of our own. It is assigned to the InnerHandler property of the HttpServer, which has been set up by the HttpControllerHandler if web hosting via Internet Information Services (IIS) is being used. If your ASP.NET Web API application is self-hosted, the plumbing gets done by the HttpSelfHostServer itself, which derives from HttpServer.
Regardless of the type of hosting chosen, the Innerhandler property of HttpServer is created by the HttpClientFactory, which creates the DelegatingHandler pipeline of your ASP.NET Web API application based on the collection of HttpMessageHandler instances in the configuration where your custom message handlers are registered (that’ll be covered later in this chapter).
The next DelegatingHandler that gets to work in the pipeline shown in Figure 10-1 is the DelegatingHandler2, which just represents an arbitrary number of DelegatingHandler implementations that could be registered for your application.
The very last handler in the pipeline is always the HttpControllerDispatcher, which is passed as a parameter to the HttpServer constructor by the HttpControllerHandler based on the Dispatcher property of the GlobalConfiguration object of the ASP.NET Web API application.
As can also be seen in Figure 10-1 (by means of the dashed arrows) and as was mentioned earlier in this chapter, the pipeline not only runs from the outermost DelegatingHandler to the innermost one but also can run back from the formerly innermost DelegatingHandler to the formerly outermost one. These handlers are accessed again in reverse order if you defined a so-called continuation on the SendAsync method of the handlers’ implementation, which is something you’ll see later in this chapter, in the “Custom Message Handlers” section.
The following section shows an implementation of DelegatingHandler (see Listing 10-4) that allows you to inspect or even modify the request. Within the continuation, which is defined inside the ContinueWith method run on the result of the base.SendAsync method, you can do the same with the response when coming back from the controller.
When the response is inspected or modified, it is handled over to the next DelegatingHandler in the client’s direction by returning it.
Now you know what HttpMessageHandler implementations are and what their purpose is in the context of an ASP.NET Web API application. Furthermore, you know how they are chained together in a pipeline that processes the instances of HttpRequestMessage and HttpResponseMessage. Now it’s time to create your own custom message handlers and learn how to register them in the application configuration.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25280)
Hello! Python by Anthony Briggs(24331)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23419)
Kotlin in Action by Dmitry Jemerov(22500)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21953)
Dependency Injection in .NET by Mark Seemann(21835)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20699)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19514)
Grails in Action by Glen Smith Peter Ledbrook(18592)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17028)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15836)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13683)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11846)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11149)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10619)
Hit Refresh by Satya Nadella(9185)
The Kubernetes Operator Framework Book by Michael Dame(8560)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8399)
Robo-Advisor with Python by Aki Ranin(8346)